<?php
defined('IN_IA') or exit('Access Denied');

$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';

wl_load()->model('goods');

if ($op == 'display') {

    $page = max(1, intval($_GPC['page']));
    $size = 10;
    $condition = " WHERE uniacid = {$_W['uniacid']} ";

    if (!empty($_GPC['keyword'])) {
        $condition .= " and gname like '%{$_GPC['keyword']}%'";
    }
    $sqlTotal = pdo_sql_select_count_from('tg_goods') . $condition;
    $sqlData = pdo_sql_select_all_from('tg_goods') . $condition ;
    $goodses = pdo_pagination($sqlTotal, $sqlData, $params, 'id', $total, $page, $size);
    $total = pdo_fetchcolumn("select count(*) from " .tablename('tg_goods') .$condition);
    $goodses = pdo_fetchall("select * from " .tablename('tg_goods') .$condition ." limit " .($page - 1) * $size ." , " .$size);
    $pager = pagination($total, $page, $size);

    foreach ($goodses as $key => &$value) {
        $merchant = pdo_fetch("SELECT name  FROM " . tablename('tg_category') . " WHERE uniacid = '{$_W['uniacid']}' and id={$value['fk_typeid']}");

        $value['typename'] = $merchant['name'];
    }

}
include wl_template('goods/goods_code');
exit();